﻿/********************************************************************************
 * Developed by Phil Tyler (http://www.laidbackcoder.co.uk)
 * 
 * Cryptosolic is Licensed under the GNU Lesser General Public License (LGPL)
 * http://cryptosolic.codeplex.com/license
 * *****************************************************************************/
using System;
using NUnit.Framework;
using Cryptosolic.Security.Encryption.Symmetric;

namespace Cryptosolic.Security.Tests
{
    [TestFixture]
    public class SymmetricDesTests : SymmetricEncryptionTestsBase
    {
        [SetUp]
        public void Setup()
        {
        	#pragma warning disable 0618
            base.encryptionAlgorithm = new Des();
            #pragma warning restore 0618
        }

        [Test]
        public void SymmetricDes_EncryptData_OutputEncryptedDataDifferentFromInput()
        {
            base.assert_EncryptData_OutputEncryptedDataDifferentFromInput();
        }

        [Test]
        public void SymmetricDes_EncryptData_OutputEncryptedDataRepeatable()
        {
            base.assert_EncryptData_OutputEncryptedDataRepeatable();
        }

        [Test]
        public void SymmetricDes_EncryptData_OutputEncryptedDataDifferentWithTwoDifferentInputs()
        {
            base.assert_EncryptData_OutputEncryptedDataDifferentWithTwoDifferentInputs();
        }

        [Test]
        public void SymmetricDes_DecryptData_SuccessfullyDecryptEncryptedData()
        {                      
            base.assert_DecryptData_SuccessfullyDecryptData();
        }
        
        [Test]
        public void SymmetricDes_DecryptData_UnsuccessfullyDecryptDataWithTwoDifferentIVs()
        {                      
            string data = "this.is.a.test";
	                    	        	
            byte[] iv1 = encryptionAlgorithm.GenerateRandomIV();
            byte[] iv2 = encryptionAlgorithm.GenerateRandomIV();
            
            string encryptedData = encryptionAlgorithm.EncryptData(data, key, iv1).ToString();
            string actual = encryptionAlgorithm.DecryptData(encryptedData, key, iv2).ToString();

            Assert.AreNotEqual(data, actual);
        }
        
        [Test]
        public void SymmetricDes_DecryptData_UnsuccessfullyDecryptDataWithTwoDifferentKeys()
        {                      
            base.assert_DecryptData_UnsuccessfullyDecryptDataWithTwoDifferentKeys();
        }
        
        [Test]
        public void SymmetricDes_EncryptData_OutputEncryptedDataDifferentWhenUsingSaltwithKey()
        {
        	base.assert_EncryptData_OutputEncryptedDataDifferentWhenUsingSaltWithKey();
        }
    }
}
